﻿using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.ObjectMapping;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
using BW.WMS.WareHouseCheck.DTO;
using Microsoft.EntityFrameworkCore;

namespace BW.WMS.WareHouseCheck
{
    public class DeptService : ApplicationService, IDeptService
    {
        private readonly IRepository<Department, Guid> _deptRepository;

        public DeptService(IRepository<Department, Guid> deptRepository)
        {
            _deptRepository = deptRepository;
        }

        /// <summary>
        /// 创建部门
        /// </summary>
        /// <param name="department"></param>
        /// <returns></returns>
        public async Task<DepartmentDTO> CreateDept(CreateDept dept)
        {
            var house = ObjectMapper.Map<CreateDept, Department>(dept);
            await _deptRepository.InsertAsync(house);
            return ObjectMapper.Map<Department, DepartmentDTO>(house);
        }

        /// <summary>
        /// 获取所有部门信息
        /// </summary>
        /// <returns>部门DTO列表</returns>
        public async Task<List<DepartmentDTO>> GetDeptList()
        {
            var deptQueryable = await _deptRepository.GetQueryableAsync();
            var deptList = deptQueryable.ToList();
            return ObjectMapper.Map<List<Department>, List<DepartmentDTO>>(deptList);
        }
    }
}
